import axios from "@/utils/requist"

// 登录获取token
export function Login(data) {

	let formData = new FormData();
	formData.append("username", data.username);
	formData.append("password", data.password);
	formData.append("uuid", data.uuid);
	formData.append("text", data.text);


	return axios({
		url: '/supersignin',
		method: 'POST',
		data: formData
	})
	
}


// 获取用户信息
export function userProfile(token){

	return axios({
		url: '/superprofile',
		method: 'GET',
		headers: { 'authorization': `Bearer ${token}`}
	})

}


// 更改用户头像
export function changeAvator(token, data) {

	let formData = new FormData()
	formData.append('avator', data)

	return axios({
		url: '/changesuperavator',
		method: 'POST',
		headers: { 'authorization': `Bearer ${token}` },
		data: formData
	})

}


// 新增管理员接口
export function addAdmin(token,data) {
	let formData = new FormData()
	formData.append('username',data)

	return axios({
		url:'/createsuperuser',
		method: 'POST',
		headers: { 'authorization': `Bearer ${token}` },
		data: formData
	})
}


// 查询管理员接口
 export function querymin(token) {
	return axios({
		method:'GET',
		url:'/superusers',
		headers: {'authorization': `Bearer ${token}` }
	})
 }


//  绑定邮箱接口
export function bindemail(token,data) {
	const params = new URLSearchParams();
	params.append('email', data)

	return axios({
		method: 'POST',
		url: '/superbindemail',
		headers: { 'authorization': `Bearer ${token}` },
		data:params
	})
}

//验证 验证码接口
export function vefity(token,code){
	return axios({
		method: 'PUT',
		url: '/superbindemail',
		headers: { 'Content-Type': `application/x-www-form-urlencoded`, 'authorization': `Bearer ${token}` },
		data: 'text='+code
	})
}

// 更改用户密码获取邮箱接口
export function changePassword(token){
	return axios({
		method: 'POST',
		url: '/superchangepwd',
		headers: {'authorization': `Bearer ${token}` },
	})
}

// 更改密码 验证验证码是否正确
export function judgePassword(token,date) {
	return axios({
		method: 'PUT',
		url: '/superchangepwd',
		headers: { 'Content-Type': `application/x-www-form-urlencoded`, 'authorization': `Bearer ${token}` },
		data: 'text=' + date.text + '&pwd1=' + date.pwd1 + '&pwd2=' + date.pwd2
	})
}